Container: Fix scrolled coord in set_focus_child()
authorDaniel Boles <dboles@src.gnome.org>
Mon, 7 Aug 2017 17:25:28 +0000 (18:25 +0100)
committerDaniel Boles <dboles@src.gnome.org>
Mon, 7 Aug 2017 17:42:15 +0000 (18:42 +0100)
Commit 885bcd9fe4b6b4ecb003570ea0520cf42ec737a9 trampled the bit here
that is meant to translate between the nominated focus child and the
actual innermost one that is used for updating the h/v adjustments.

So, we need to save the passed focus child before diving into its
children, then translate and get allocations between them both. This
makes GTK+ 4 behave like GTK+ 3 again: instead of priv->focus_child and
focus_child, we now have focus_child and child, serving the roles of the
nominated focus child and its innermost focus child respectively.

This also ditches the unnecessary call to Widget:get_focus_child(), as
Container::set_focus_child() gets that same new child as an argument.

gtk/gtkcontainer.c

index 0a2dbf9aec426fdb5c40ebff4236d839af2bfdd6..bc52c9955451a0c5769d91284968e99b48c89c71 100644 (file)
@@ -2032,15 +2032,11 @@ gtk_container_compute_expand (GtkWidget         *widget,
 }
 
 static void
-gtk_container_real_set_focus_child (GtkContainer     *container,
-                                    GtkWidget        *child)
+gtk_container_real_set_focus_child (GtkContainer *container,
+                                    GtkWidget    *focus_child)
 {
-  GtkWidget *focus_child;
-
   g_return_if_fail (GTK_IS_CONTAINER (container));
-  g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
-
-  focus_child = gtk_widget_get_focus_child (GTK_WIDGET (container));
+  g_return_if_fail (focus_child == NULL || GTK_IS_WIDGET (focus_child));
 
   /* check for h/v adjustments
    */
@@ -2055,17 +2051,19 @@ gtk_container_real_set_focus_child (GtkContainer     *container,
       vadj = g_object_get_qdata (G_OBJECT (container), vadjustment_key_id);
       if (hadj || vadj)
         {
-          while (gtk_widget_get_focus_child (focus_child))
-            focus_child = gtk_widget_get_focus_child (focus_child);
+          GtkWidget *child = focus_child;
+
+          while (gtk_widget_get_focus_child (child))
+            child = gtk_widget_get_focus_child (child);
 
-          gtk_widget_translate_coordinates (focus_child, focus_child,
+          gtk_widget_translate_coordinates (child, focus_child,
                                             0, 0, &x, &y);
 
           _gtk_widget_get_allocation (focus_child, &allocation);
           x += allocation.x;
           y += allocation.y;
 
-          _gtk_widget_get_allocation (focus_child, &allocation);
+          _gtk_widget_get_allocation (child, &allocation);
 
           if (vadj)
             gtk_adjustment_clamp_page (vadj, y, y + allocation.height);